package me.ywd.comparison.component;

import me.ywd.comparison.domain.Track;
import me.ywd.comparison.model.MongoTrack;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;

/**
 * @Author Ye_Wenda
 * @Date 7/25/2017
 */
@Component
public class TrackGenerator {

    private String[] areas = new String[]{"areaA", "areaB", "sectionX", "domainY", "distinctM", "distinctN"};

    public Track mockTrack(Integer trackId, Date trackTime) {
        Random r = new Random();
        Track track = new Track();
        track.setTrackId(trackId);
        track.setTrackTime(trackTime);
        track.setArea(areas[r.nextInt(5)]);
        track.setX(Math.round(r.nextDouble() * 100) / 100.0);
        track.setY(Math.round(r.nextDouble() * 100) / 100.0);
        track.setZ(Math.round(r.nextDouble() * 100) / 100.0);
        return track;
    }

    public MongoTrack convert(Track track) {
        MongoTrack mongoTrack = new MongoTrack();
        mongoTrack.setTrackId(track.getTrackId());
        mongoTrack.setTrackTime(track.getTrackTime());
        mongoTrack.setArea(track.getArea());
        mongoTrack.setX(track.getX());
        mongoTrack.setY(track.getY());
        mongoTrack.setZ(track.getZ());
        return mongoTrack;
    }

    public Track convert(MongoTrack mongoTrack) {
        Track track = new Track();
        track.setTrackId(mongoTrack.getTrackId());
        track.setTrackTime(mongoTrack.getTrackTime());
        track.setArea(mongoTrack.getArea());
        track.setX(mongoTrack.getX());
        track.setY(mongoTrack.getY());
        track.setZ(mongoTrack.getZ());
        return track;
    }
}
